package com.sky.controller.admin;


import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.IDishService;
import com.sky.vo.DishPageVO;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Path;
import java.util.List;

/**
 * <p>
 * 菜品 前端控制器
 * </p>
 *
 * @author xieminghui
 * @since 2023-11-16
 */
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Resource
    private IDishService iDishService;
    /**
     * 分页查询菜品
     * @author: XieMingHui
     * @date: 23/11/20 9:28:06
     * @param: [分页查询条件对象]
     * @return: 返回通用Json对象
     **/
    @GetMapping("/page")
    public Result<DishPageVO> findDishPage( DishPageQueryDTO dishPageQueryDTO){
       return iDishService.findDishPage(dishPageQueryDTO);
    }
    /**
     * 新增菜品
     * @author: XieMingHui
     * @date: 23/11/20 9:29:16
     * @param: 菜品请求参数对象
     * @return: 通用JSON,新增成功无数据返回
     **/
    @PostMapping
    public Result<String> saveDish(@RequestBody DishDTO dishDTO){
        return iDishService.saveDish(dishDTO);
    }
    /**
     * 修改菜品
     * @author: XieMingHui
     * @date: 23/11/20 9:29:16
     * @param: 菜品请求参数对象
     * @return: 通用JSON,新增成功无数据返回
     **/
    @PutMapping
    public Result<String> updateDish(@RequestBody DishDTO dishDTO){
        return iDishService.updateDish(dishDTO);
    }
    /**
     * 修改菜品查询回显
     * @author: XieMingHui
     * @date: 23/11/20 10:12:53
     * @param: 菜品id
     * @return: 菜品信息
     **/
    @GetMapping("/{id}")
    public  Result<DishVO> findById(@PathVariable Long id){
       return iDishService.findById(id);
    }
    /**
     * 起售和禁售菜品
     * @author: XieMingHui
     * @date: 23/11/20 11:59:10
     * @param: 路径占位符和字符串参数
     * @return: 返回通用对象,数据:操作成功
     **/
    @PostMapping("/status/{status}")
    public Result<String> enableDisable(@PathVariable String status, Long id){
        return iDishService.enableDisable(status,id);
    }
    /**
     * 删除菜品
     * @author: XieMingHui
     * @date: 23/11/20 12:18:27
     * @param: 菜品id
     * @return: 操作结果
     **/
    @DeleteMapping
    public Result<String> deleteDish(@RequestParam List<Long> ids){
        return iDishService.deleteDish(ids);
    }
    /**
     * 根据分类查询菜品
     * @author: XieMingHui
     * @date: 23/11/20 17:57:23
     * @param: 菜品分类id
     * @return: 菜品信息
     **/
    @GetMapping("/list")
    public Result<List<DishVO>> findDishByCategory(@RequestParam  Integer categoryId){
        return iDishService.findDishByCategory(categoryId);
    }
}
